package com.javaee.exam.utils;

import java.io.Serializable;

import org.codehaus.jackson.map.annotate.JsonSerialize;

@SuppressWarnings("serial")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ServicesResponse<T> implements Serializable {
	private Integer code;
	private String msg;
	private T data;
	private Integer count;// 当表总行数
	private Integer limit;// 每页显示条数

	public ServicesResponse() {
	}

	public ServicesResponse(Integer code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}

	public ServicesResponse(Integer code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public ServicesResponse(Integer code, String msg, T data, Integer count) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
		this.count = count;
	}

	public static <T> ServicesResponse<T> success(Integer code, String msg) {
		return new ServicesResponse<T>(code, msg);
	}

	public static <T> ServicesResponse<T> success(Integer code, String msg, T t) {
		return new ServicesResponse<>(code, msg, t);
	}

	public static <T> ServicesResponse<T> success(Integer code, String msg, T t, Integer count) {
		return new ServicesResponse<>(code, msg, t, count);
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Integer getLimit() {
		return limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public static ServicesResponse error(int code, String msg) {
		return new ServicesResponse<>(code, msg);
	}

}
